package diona.search

import xml.Node

/**
 * User: anton
 * Date: 23.07.11 20:23
 */
class FoafProfile(val name: Option[String] = None,
                  val weblogs: Seq[String] = Nil,
                  val country: Option[String] = None,
                  val city: Option[String] = None,
                  val region: Option[String] = None
                   )

object FoafProfile
{
  def apply(rdf: Node): FoafProfile =
  {
    (rdf \ "Person") match {
      case Seq(p, _) => createFoaf(p)
      case Seq(p) => createFoaf(p)
      case _ => new FoafProfile()
    }
  }

  private def createFoaf(p: Node): FoafProfile =
  {
    new FoafProfile(
      name = (p \ "name").headOption.map(_.text),
      weblogs = (p \ "weblog" \ "@{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource").map(_.text),
      country = (p \ "country" \ "@{http://purl.org/dc/elements/1.1/}title").headOption.map(_.text),
      city = (p \ "city" \ "@{http://purl.org/dc/elements/1.1/}title").headOption.map(_.text),
      region = (p \ "region" \ "@{http://purl.org/dc/elements/1.1/}title").headOption.map(_.text)
    )
  }
}
